package com.zg.message.channel;

import com.zg.common.core.dao.message.entity.MsgInfo;
import com.zg.message.service.MsgInfoService;
import com.zg.message.sys.SendStateEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/7/9 14:43
 */
@Service
@Slf4j
public class EmailChannel implements IChannel {

    @Autowired
    private MsgInfoService msgInfoService;
    @Override
    public boolean send(MsgInfo msgInfo) {
        String state = SendStateEnum.SUCCESS.getValue();
        try {
            log.info("send email");
            return true;
        } catch (Exception e) {
            log.error("发送短信异常：{}", e.getMessage());
            state = SendStateEnum.FAIL.getValue();
            return false;
        } finally {
            msgInfo.setSendTime(new Date());
            msgInfo.setSendState(state);
            msgInfoService.edit(msgInfo);
        }
    }
}
